package com.study.commomThirdPartyTechnologies.common.config;

import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class CommonOkHttpClientConfig {

    @Bean("commonOkHttp")
    public OkHttpClient OkHttpClient() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(10L, TimeUnit.MINUTES);
        builder.readTimeout(10L, TimeUnit.MINUTES);
        Dispatcher dispatcher = new Dispatcher();
        dispatcher.setMaxRequestsPerHost(50000);
        dispatcher.setMaxRequests(50000);
        builder.dispatcher(dispatcher);
        return builder.build();
    }

}
